{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pandas in c:\\programdata\\anaconda3\\lib\\site-packages (1.0.5)\n",
      "Requirement already satisfied: python-dateutil>=2.6.1 in c:\\programdata\\anaconda3\\lib\\site-packages (from pandas) (2.8.1)\n",
      "Requirement already satisfied: numpy>=1.13.3 in c:\\programdata\\anaconda3\\lib\\site-packages (from pandas) (1.18.5)\n",
      "Requirement already satisfied: pytz>=2017.2 in c:\\programdata\\anaconda3\\lib\\site-packages (from pandas) (2020.1)\n",
      "Requirement already satisfied: six>=1.5 in c:\\programdata\\anaconda3\\lib\\site-packages (from python-dateutil>=2.6.1->pandas) (1.15.0)\n"
     ]
    }
   ],
   "source": [
    "!pip install pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原始数据:\n",
      "     a   b   c\n",
      "0  12  12   7\n",
      "1  17   6  19\n",
      "2   2   8  17\n",
      "每列求和聚合:\n",
      " a    31\n",
      "b    26\n",
      "c    43\n",
      "dtype: int64\n",
      "每列同时求和及平均值聚合:\n",
      "               a          b          c\n",
      "sum   31.000000  26.000000  43.000000\n",
      "mean  10.333333   8.666667  14.333333\n",
      "各行分别求和.平均值和极差聚合:\n",
      " 0    31.0\n",
      "1    14.0\n",
      "2    15.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "arr = np.random.randint(1, 20, size=(3, 3))\n",
    "df = pd.DataFrame(arr, columns=['a','b','c'])\n",
    "print('原始数据:\\n', df)\n",
    "print('每列求和聚合:\\n', df.agg('sum'))\n",
    "print('每列同时求和及平均值聚合:\\n', df.agg(['sum','mean']))\n",
    "def rang(arr):\n",
    "    return arr.max() - arr.min()\n",
    "print('各行分别求和.平均值和极差聚合:\\n',df.agg({0:'sum',1:'mean',2:rang}, axis=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
